//
//  PersonalHomeCellUserView.m
//  OnionHome
//
//  Created by fengjie on 2019/9/24.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PersonalHomeCellUserView.h"

@implementation PersonalHomeCellUserView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
-(void)createUI{
    [self addSubview:self.iconImage];
    [self addSubview:self.userName];
    [self addSubview:self.dynamicData];
    [self addSubview:self.deleButton];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.width.height.mas_equalTo(40);
        make.bottom.mas_equalTo(-16);
    }];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImage.mas_right).offset(12);
        make.top.mas_equalTo(self.iconImage);
    }];
    [self.dynamicData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImage.mas_right).offset(12);
        make.bottom.mas_equalTo(self.iconImage);
    }];
    [self.deleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.iconImage);
    }];

}

/// 进入用户个人中心页面
-(void)pushUserContenPage{
    
}
#pragma mark --懒加载

-(UIImageView*)iconImage{
    if(!_iconImage){
        _iconImage=[UIImageView new];
        _iconImage.layer.cornerRadius = 20;
        _iconImage.image = IMAGE_NAMED(@"userIconDefut");
        _iconImage.layer.masksToBounds = YES;
        _iconImage.userInteractionEnabled = YES;
        [_iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushUserContenPage)]];
    }
    return _iconImage;
}
-(UILabel*)userName{
    if(!_userName){
        _userName=[UILabel new];
        _userName.font = SYSTEMFONT(14);
        _userName.textColor = UIColorFromRGB(0x273323);
        _userName.text = @"我是大舌头";
        _userName.userInteractionEnabled = YES;
        [_userName addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushUserContenPage)]];

    }
    return _userName;
}
-(UILabel*)dynamicData{
    if(!_dynamicData){
        _dynamicData=[UILabel new];
        _dynamicData.font = SYSTEMFONT(12);
        _dynamicData.textColor = UIColorFromRGB(0x959E97);
        _dynamicData.text = @"昨天 14:15";

    }
    return _dynamicData;
}
-(UIButton*)deleButton{
    if(!_deleButton){
        _deleButton=[UIButton buttonWithType:UIButtonTypeCustom];
        [_deleButton setBackgroundImage:IMAGE_NAMED(@"sangedian") forState:UIControlStateNormal];
        kWeakSelf(weakSelf);
        [_deleButton addActionHandler:^{
            
            FJAlertController * vc = [FJAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
            FJAlertAction * action = [FJAlertAction actionWithTitle:@"置顶" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            FJAlertAction * action1 = [FJAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            FJAlertAction * action2 = [FJAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];

            [vc addAction:action];
            [vc addAction:action1];
            [vc addAction:action2];
            action.textColor = UIColorFromRGB(0x009966);
            action1.textColor = UIColorFromRGB(0x009966);
            action2.textColor = UIColorFromRGB(0x009966);
            
            [[weakSelf getCurrentViewController] presentViewController:vc animated:YES completion:nil];

        }];
    }
    return _deleButton;
}
@end
